<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户信息管理系统</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <!-- <script src="js/bootstrap.min.js"></script>-->
    <style type="text/css">
        td, th {
            text-align: center;
        }

    </style>
</head>
<body>
<div class="container">
    <h3 style="text-align: center;margin-bottom: 50px;">用户信息列表</h3>
    <div style="float: left;">
        <form class="form-inline">
            <div class="form-group">
                <label for="ipt_name">姓名</label>
                <input name="name" type="text" class="form-control" id="ipt_name">
            </div>
            <div class="form-group">
                <label for="ipt_address">籍贯</label>
                <input name="address" type="text" class="form-control" id="ipt_address">
            </div>
            <div class="form-group">
                <label for="ipt_email">邮箱</label>
                <input name="email" type="email" class="form-control" id="ipt_email">
            </div>
            <button id="submit1" type="button" class="btn btn-default" onclick="mysearch()">查询</button>
        </form>
    </div>
    <div style="float: right;margin-bottom: 15px">
        <a class="btn btn-primary" href="add.html">添加用户</a>
        <a id="delete" class="btn btn-primary" href="javascript:delByIds()">删除选中</a>
    </div>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>选择</th>
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>籍贯</th>
            <th>QQ</th>
            <th>邮箱</th>
            <th>超管</th>
            <th>操作</th>
        </tr>
        <tbody id="info">

        </tbody>
    </table>
    <div>
        <nav aria-label="Page navigation">
            <ul id="all" class="pagination">
                <li><a href="javascript:firstPage();">首页</a></li>
                <li><a href="javascript:beforePage();">上一页</a></li>
                <li><a href="javascript:nextPage();">下一页</a></li>
                <li><a href="javascript:lastPage();">末页</a></li>
                <span id="pageinfo" style="font-size: 20px;margin-left: 10px;">
                                  </span>
            </ul>
        </nav>
    </div>
</div>
<script>
    // 查询 url 中的某个参数的值
    function getParamValue(key){
        var url = location.search;
        if(url!=""){
            url = url.substr(1);
            var kvs = url.split("&");
            for(var i=0;i<kvs.length;i++){
                var kv = kvs[i].split("=");
                if(key==kv[0]) return kv[1];
            }
        }
        return "";
    }
    // 定义参数
    var username ="";
    var address ="";
    var email ="";
    var totalPage = 3; // 总页数
    var totalCount = 0; // 总条数
    var pindex = 1; // 当前页码
    var psize = 2; // 每页显示条数
    // 获取用户列表
    function getList(){
        jQuery.ajax({
            url:"listbypage",
            type:"GET",
            data:{
                "pindex":pindex,
                "psize":psize,
                "username":username,
                "address":address,
                "email":email
            },
            success:function(result){
                if(result!=null && result.data!=null){
                    totalCount = result.data.count;
                    totalPage = Math.ceil(parseInt(totalCount)/psize);
                    jQuery("#pageinfo").html("共 "+totalCount+" 条记录，共 "+totalPage+" 页");
                    var listDiv = "";
                    if(result.data.list.length>0){
                        for(var i=0;i<result.data.list.length;i++){
                            var userinfo = result.data.list[i];
                            listDiv +='<tr>';
                            listDiv +='<th>';
                            listDiv +='<input id="'+userinfo.uid+'" type="checkbox"></th>';
                            listDiv +='<th>'+userinfo.uid+'</th>';
                            listDiv +='<th>'+userinfo.username+'</th>';
                            listDiv +='<th>'+userinfo.sex+'</th>';
                            listDiv +='<th>'+userinfo.age+'</th>';
                            listDiv +='<th>'+userinfo.address+'</th>';
                            listDiv +='<th>'+userinfo.qq+'</th>';
                            listDiv +='<th>'+userinfo.email+'</th>';
                            listDiv +='<th>'+(userinfo.isadmin==true?"是":"否")+'</th>';
                            listDiv +='<th>';
                            listDiv +='<a class="btn btn-default btn-sm" href="update.html?uid='+userinfo.uid+'">修改</a>';
                            listDiv +='<a class="btn btn-default btn-sm" href="javascript:mydel('+userinfo.uid+');">删除</a>';
                            listDiv +='</th></tr>';
                        }
                    }
                    jQuery("#info").html(listDiv);
                }
            }
        });
    }
    getList();

    // 删除方法 
    function mydel(uid){
        alert(uid);
    }
</script>
</body>

</html>
